Ext.onReady(function() {

    var bd = Ext.getBody();

    var asyncCt = function() {
        var d = Ext.get('async-ct');
        if (!d) {
            bd.createChild({
                tag: 'h2',
                html: 'Asynchronous ajax request'
            });
            bd.createChild({
                tag: 'div',
                id: 'async-ct',
                html: ''
            });
            d = Ext.get('async-ct');
        }
        return d;
    }();

    Ext.Ajax.request({
        url: 'syncrequest.json',
        success: function(response, options) {
            var resp = Ext.decode(response.responseText);
            asyncCt.createChild({
                tag: 'p',
                html: resp.message + ', 后执行'
            });
        }
    });

    asyncCt.createChild({
        tag: 'p',
        html: '我先执行'
    });

    var syncCt = function() {
        var d = Ext.get('sync-ct');
        if (!d) {
            bd.createChild({
                tag: 'h2',
                html: 'Synchronous ajax request'
            });
            bd.createChild({
                tag: 'div',
                id: 'sync-ct',
                html: ''
            });
            d = Ext.get('sync-ct');
        }
        return d;
    }();

    Ext.Ajax.request({
        url: 'syncrequest.json',
        async: false,
        success: function(response, options) {
            var resp = Ext.decode(response.responseText);
            syncCt.createChild({
                tag: 'p',
                html: resp.message + ', 先执行'
            });
        }
    });

    syncCt.createChild({
        tag: 'p',
        html: '等待同步AJAX请求响应后才执行'
    });

});
